<template>
  <div class="goods-item" @click="itemClick">
    <!-- <img class="img" :src="goodsItem.show.img" alt="" /> -->
    <img class="img" v-lazy="showImage" alt="" />
    <p class="title">{{ goodsItem.title }}</p>
    <span class="price">¥{{ goodsItem.price }}</span>
    <span class="collect">☆{{ goodsItem.cfav }}</span>
  </div>
</template>

<script>
export default {
  props: {
    // 传入每个单独的goods-item对象
    goodsItem: {
      type: Object,
      defaullt() {
        return {};
      },
    },
  },
  computed: {
    showImage() {
      return this.goodsItem.image || this.goodsItem.show.img;
    },
  },
  methods: {
    itemClick() {
      this.$router.push({
        path: "/detail",
        query: { iid: this.goodsItem.iid },
      });
    },
  },
};
</script>

<style scoped  lang='less'>
.goods-item {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #999;
  padding: 10px;
  margin-bottom: 10px;
  width: 40%;
  font-size: 14px;
  img {
    width: 100%;
  }
  .title {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    word-break: break-all;
    color: #111;
  }
  .price {
    color: red;
    margin-right: 10px;
  }
}
</style>
